package g4p.newg4p;

import g4p_controls.G4P;
import g4p_controls.GAlign;
import g4p_controls.GButton;
import g4p_controls.GCScheme;
import g4p_controls.GDropList;
import g4p_controls.GEvent;
import g4p_controls.GLabel;
import g4p_controls.GOption;
import g4p_controls.GToggleControl;
import g4p_controls.GToggleGroup;
import processing.core.PApplet;
import processing.core.PImage;

public class TextWithIcon_Controls_Test extends PApplet {

	PImage bimg;
	
	GLabel lbl0, lbl1;
	GButton btn0, btn1;
	GOption opt0, opt1, opt2;
	
	GToggleGroup tg = new GToggleGroup();
	// Text and icon alignment option controls
	GLabel cta, cia;


	GDropList textH, textV, iconH, iconV;

	public void setup(){
		size(600,400);
		cursor(CROSS);
//		G4P.messagesEnabled(false);
		G4P.setGlobalColorScheme(GCScheme.RED_SCHEME);
	
		bimg = loadImage("g4p/bground.jpg");
		
	//	String s = "Peter Lager is a very nice guy living in Wales.";

		lbl0 = new GLabel(this, 20, 80, 100, 80, "This label has text only");
		lbl0.setOpaque(true);
		lbl0.tag = "l0 ";
		
		lbl1 = new GLabel(this, 220, 80, 130, 80, "This label has both text and an icon");
		lbl1.setOpaque(true);
		lbl1.setIcon("g4p/bugs/bugtest.png", 1, GAlign.LEFT, null);
		lbl1.tag = "l1 ";

		btn0 = new GButton(this, 20, 220, 100, 80, "Button with text only");
		btn0.tag = "b0 ";
		
		btn1 = new GButton(this, 220, 220, 130, 80, "Button with text and icon");
		btn1.setIcon("g4p/smile.png", 3, GAlign.LEFT, null);
		btn1.tag = "b1 ";

		opt0 = new GOption(this, 20, 10, 100, 20, "Option 0");
		opt0.setOpaque(true);
		opt0.tag = "opt0";
		tg.addControl(opt0);

		opt1 = new GOption(this, 20, 32, 100, 20, "Option 1");
		opt1.setOpaque(true);
		opt1.tag = "opt1";
		tg.addControl(opt1);

		opt2 = new GOption(this, 20, 54, 100, 20, "Option 2");
		opt2.setOpaque(true);
		opt2.tag = "opt2";
		tg.addControl(opt2);

		opt0.setSelected(true);

		makeDropListControls();
	}


	public void draw(){
		background(220);
		image(bimg,0,0);
	}

	public void handleButtonEvents(GButton buton, GEvent event) { }


	public void handleDropListEvents(GDropList droplist, GEvent event) {
		int n = droplist.getSelectedIndex();
		if(droplist == iconV || droplist == textV )
			n += 16;
		GAlign na = GAlign.getFromID(droplist.getSelectedIndex());
		println(na);

		if(droplist == textH || droplist == iconH){
			lbl0.setTextAlign(na, null);
			lbl1.setTextAlign(na, null);
			btn0.setTextAlign(na, null);
			btn1.setTextAlign(na, null);
			opt0.setTextAlign(na, null);
			opt1.setTextAlign(na, null);
			opt2.setTextAlign(na, null);
		}
		else if(droplist == textV || droplist == iconV){
			lbl0.setTextAlign(null, na);
			lbl1.setTextAlign(null, na);
			btn0.setTextAlign(null, na);
			btn1.setTextAlign(null, na);
			opt0.setTextAlign(null, na);
			opt1.setTextAlign(null, na);
			opt2.setTextAlign(null, na);
		}

	}
	
	public void handleToggleControlEvents(GToggleControl option, GEvent event) { 
		System.out.println(option.tag + "  " + event);
	}
	

	/**
	 * Make the droplists 
	 */
	public void makeDropListControls(){
		// Text alignment options
		cta = new GLabel(this, 420,20, 100, 18, "Text Alignment");
		cta.setOpaque(true);
		String[] items;
		
		items = new String[] { "LEFT", "CENTER", "RIGHT", "JUSTIFY"};
		textH = new GDropList(this, 420, 40, 100, 90, 4);
		textH.setItems(items, 1);
		textH.tag = "textH";
		
		items = new String[] { "TOP", "MIDDLE", "BOTTOM"};
		textV = new GDropList(this, 420, 60, 100, 90, 4);
		textV.setItems(items, 1);
		textV.tag = "textV";
		// Icon alignment options
		cia = new GLabel(this, 420, 100, 100, 18, "Icon Alignment");
		cia.setOpaque(true);
		
		items = new String[] { "LEFT", "CENTER", "RIGHT", "JUSTIFY"};
		iconH = new GDropList(this, 420, 120, 100, 90, 4);
		iconH.setItems(items, 2);
		iconH.tag = "iconH";
		
		items = new String[] { "TOP", "MIDDLE", "BOTTOM"};
		iconV = new GDropList(this, 420, 140, 100, 90, 4);
		iconV.setItems(items, 1);
		iconV.tag = "iconV";
		// Set draw order for combos's
	}
}
